package com.cloud.pora.mrm.web.common.filter;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet Filter implementation class MrmFilter
 */
//@WebFilter(filterName = "MrmFilter", urlPatterns = {"/*"})
public class MrmFilter implements Filter {

    /**
     * Caracter encoding filter
     * @param request
     * @param response
     * @param chain
     * @throws IOException
     * @throws ServletException 
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("UTF-8");
        //response.setCharacterEncoding("UTF-8");

        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;

        // System.out.println("RealPath : " + httpRequest.getRequestURL());
        StringBuffer requestUrl = httpRequest.getRequestURL();

        /*
        if (httpRequest.getScheme().toLowerCase().equals("http")) {
            requestUrl.replace(0, 4, "https");
            httpResponse.sendRedirect(requestUrl.toString());
            return;
        }
        */
        
        chain.doFilter(request, response);
    }

    @Override
    public void init(FilterConfig fc) throws ServletException {
    }

    @Override
    public void destroy() {
    }
	
}
